home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 121_01 / call.c < prev    next >
Text File  |  1985-08-19  |  5KB  |  116 lines

  1. /*
  2. HEADER: CUG 121.??;
  3.  
  4.     TITLE:    Call - dial phone numbers;
  5.     VERSION:    1.0;
  6.     DATE:    12/01/85;
  7.     DESCRIPTION: "Call is a program which uses the auto-dial features of the
  8.         Hayes Smartmodem to dial phone numbers by name."
  9.     KEYWORDS:    modem, dial;
  10.     SYSTEM:    CP/M;
  11.     FILENAME:    CALL.C;
  12.     WARNINGS:    "Copyright (c) 1981, Mike W. Meyer.
  13.         Requires local.c for link.
  14.         Uses Hayes Smartmodem or compatible.  Recommended switch
  15.         settings for the Smartmodem are: switches 2, 3, 4 down,
  16.         others as required by system."
  17.     SEE-ALSO:    CALL.DAT (phone number file), CALL.NRO (unformatted doc
  18.         file), CALL.DOC (formatted doc file);
  19.     AUTHORS:    Mike W. Meyer;
  20.     COMPILERS:    BDS-C 1.50;
  21. */
  22.  
  23. /*    This toy takes two arguments, the second of which is optional.
  24.  *    The first argument is the name of the system that you want to talk
  25.  *    to. See the next paragraph for more on this.  The second argument
  26.  *    is the name of a com file that you want the thing to run when it
  27.  *    gets the dial tone.  If this argument is missing, it runs the name
  28.  *    given in the DEFFCOM define.  Alternately, this argument could be
  29.  *    a '-', which causes it to return to the ccp.  Note that the call
  30.  *    usually gets you into this program BEFORE the system on the other end
  31.  *    answers the phone.  For telnet, this is nice, as you get to see the
  32.  *    response from the smartmodem.  For other things, this may be unwished
  33.  *    for.  If so, delete the V1 from the Dial command string, and then wait
  34.  *    for the modem port to have a character for you.  It should be a '4'.
  35.  *
  36.  *    Now, as for the system name you type at it.  This is compared with a
  37.  *    list of names in the file DATAFILE.  The names appear as the first
  38.  *    field in each entry, one entry per line in the file.  The format of
  39.  *    the entries is "name:number:flags:comments".  Name is the previously
  40.  *    mentioned system name.  Number is the number that the smartmodem needs
  41.  *    to dial.  Flags are the flags to be passed to the modem after dialing.
  42.  *    The problem here is that there are three places to put flags on
  43.  *    the dial command.  These are:
  44.  *
  45.  *        1) before the number
  46.  *        2) after the number
  47.  *        3) after the number/semicolon pair, terminated by an 'O'
  48.  *
  49.  *    In practice, the only thing that appears in position #2 is an 'R',
  50.  *    which is used when you want to call an originate-only modem. Thus,
  51.  *    there are several things you can do here.  You could ignore the flag
  52.  *    field entirely, and just put the whole mess in the number field. You
  53.  *    can also mix and match, with 1 always in the number field, & a ';'
  54.  *    between positions #2 and #3 at all times.  If you start changing the
  55.  *    code, things get truly wild.  I think that the best way to handle this
  56.  *    is to put all the flags that can go after the number in the flags
  57.  *    field, with a ';' terminating the number and the 'R' if it's there,
  58.  *    with a final flag of 'O', which forces the modem to go online.
  59.  *    Anything that has to go in front of the number can be put in the
  60.  *    number field.
  61.  *
  62.  *    As to actual usage, the code likes to have the Smartmodem with E0 set
  63.  *    before the code starts running.  Since this is settable via the front
  64.  *    panel (?) switches, this is not a problem, though it can be an
  65.  *    inconvenience.  I don't know that the code will die if the modem
  66.  *    echoes, but you can't test the results from modem commands very well.
  67.  *
  68.  *    Recommended switch settings for the Smartmodem are:
  69.  *        switches 2, 3, 4 down
  70.  *        others as required by system
  71.  */
  72. #include <bdscio.h>
  73. #include <hardware.h>
  74.  
  75. #define DATAFILE    "call.dat"
  76. #define DEFFCOM        "telnet"
  77.  
  78. main(argc, argv)
  79. char **argv;
  80. {
  81. char *flags, *number, file[BUFSIZ], buf[MAXLINE], *command;
  82.  
  83.     if (argc < 2 || argc > 3)
  84.         barf("usage: call <system> [-|<command>]\n");
  85.     if (argc == 2)
  86.         command = DEFFCOM;
  87.     else if (argv[2][0] == '-')
  88.         command = NULL;
  89.     else command = argv[2];
  90.  
  91.     /* make the modem look like I like it */
  92.     setup() ;
  93.     if (fopen(DATAFILE, file) == ERROR)
  94.         barf("Can't open data file!\n");
  95.     if (!findline(file, buf, strlower(argv[1])))
  96.         barf("I don't know the number for that system!\n");
  97.     if (sscanf(buf, "%*s:%s:%s:", number, flags) < 2)
  98.         *flags = NULL;
  99.     sprintf(buf, "AT V1 D%s %s\r", number, flags);
  100.     hayesput(buf);
  101.     if (command)
  102.         exec(command);
  103. }
  104.  
  105. /*
  106.  * setup - make the modem look nice for me...
  107.  */
  108. setup()
  109. {
  110.     /*
  111.      * would you believe quiet mode (V0), with a pulse phone (P), and
  112.      *    a '.' for the escape character?
  113.      */
  114.     hayesput("AT V0 P S2=46\r");
  115. }
  116.